package pl.nazaweb.imedproplus.rest;

import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import pl.nazaweb.imedproplus.business.service.Icd9Service;
import pl.nazaweb.imedproplus.rest.pojo.Icd9Pojo;
import pl.nazaweb.imedproplus.rest.pojo.ResponsePojo;

@Stateless
@Path("/json/icd9")
public class Icd9 {

    @EJB
    private Icd9Service icd9Service;

    @GET
    @Path("/get")
    @Produces(MediaType.APPLICATION_JSON)
    public ResponsePojo getIcd9List(@QueryParam("page") int page, @QueryParam("start") int start, @QueryParam("limit") int limit) {
        ResponsePojo response = new ResponsePojo();
        try {
            int[] range = {start, page*limit};
            List<Icd9Pojo> result = new ArrayList<Icd9Pojo>();
            for (pl.nazaweb.imedproplus.model.entity.Icd9 entity : this.icd9Service.getIcd9List(range)) {
                result.add(new Icd9Pojo(entity.getCode(), entity.getName(), entity.getStatus()));
            }
            response.data = result;
            response.success = true;
        } catch (Exception e) {
            response.success = false;
            response.message = e.getMessage();
        }
        return response;
    }
}
